//
//  AVRequest+Comment.m
//  项目三
//
//  Created by rimi1 on 2016/12/12.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "AVRequest+Comment.h"

@implementation AVRequest (Comment)

+ (void)avCommentWithObj:(AVObject *)obj queryArr:(QueryArr)queryArr {
    AVRelation *relation = [obj relationForKey:@"commentList"];
    AVQuery *query = [relation query];
    [query includeKey:@"user"];
    [AVRequest avQueryWithQuery:query queryArr:^(NSArray *objects, NSError *error) {
        queryArr(objects, error);
    }];
}

+ (void)avAddCommentWithObj:(AVObject *)obj content:(NSString *)content aSucceed:(AVSucceed)aSucceed {
    AVObject *commentObj = [AVObject objectWithClassName:@"Comment"];
    [commentObj setObject:content forKey:@"content"];
    // 关联动态，和用户
    [commentObj setObject:obj forKey:@"dynamic"];
    AVObject *myUser = [AVObject objectWithClassName:@"MyUser" objectId:[MyUser sharedUser].userId];
    [commentObj setObject:myUser forKey:@"user"];
    
    [AVRequest avSaveAllAddWithObj:obj key:@"commentList" objArr:@[commentObj] aSucceed:^(BOOL succeed, NSError *error) {
        aSucceed(succeed, error);
    }];
}

@end











